package com.fanyang.study.controller;

import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/model")
public class DashScopeChatModelController {
    private static final String DEFAULT_PROMPT = "你好，介绍下你自己吧。";
    private final ChatModel dashScopeChatModel;

    public DashScopeChatModelController(ChatModel chatModel) {
        this.dashScopeChatModel = chatModel;
    }
    /**
     * 简单的聊天接口
     *
     * @param msg
     * @return
     */
    @GetMapping("/simple/chat")
    public String simpleChat(@RequestParam("msg") String msg) {
        UserMessage userMessage = new UserMessage(msg);
        return dashScopeChatModel.call(userMessage);
    }
    /**
     * 流式聊天接口
     *
     * @param msg
     * @return
     */
    @GetMapping("/stream/chat")
    public Flux<String> streamChat(@RequestParam("msg") String msg) {

        return dashScopeChatModel.stream(msg);
    }
}
